<?php require_once 'source.php';?>
<?php require_once 'config.php';?>
<?php require_once 'dao/dao_db.php';?>
<?php require_once 'dao/dao_thesis.php';?>
<?php 
function default_teacher($loop_teacher,$teacher){
		if($loop_teacher==$teacher){
			echo "selected=\"selected\"";
		}
}
function default_sort($d_value,$key_sort){
	if(isset($key_sort)){
		if($d_value==$key_sort){
			echo "selected=\"selected\"";
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo SYSTITLE?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/datepicker/WdatePicker.js"></script>
</head>
<body>
<div class="wrapper">
<?php require_once 'header.php';?>
<div id="layout">
	<div id="leftlay"><?php require_once 'leftnav.php';?></div>
	<div id="rightlay">
		<div class="columntitle"><?php echo THESISMANAGE?></div>
		<div class="columncontent">
			<div>
			<?php 
				if(!isset($_SESSION['userid'])||($_SESSION['level']!=ADMINISTRATOR&&$_SESSION['level']!=TEACHER)){
					header("LOCATION:error.php?errcode=2");
				}
				if(isset($_SESSION['key_year'])&&isset($_SESSION['key_sort'])){
					$key_year=$_SESSION['key_year'];
					if(isset($_SESSION['key_teacher'])){
					$key_teacher=$_SESSION['key_teacher'];	
					}
					$key_sort=$_SESSION['key_sort'];
				}else{
					$key_year=date("Y");
				}
			?>
			<form action="service/service_search_thesis.php" method="post">
				<span><?php echo THESISYEAR?>:</span>
				<input type="text" name="key_year" 
				onfocus="WdatePicker({dateFmt:'yyyy',readOnly:true,isShowClear:false})" 
				class="Wdate" readonly="readonly" value="<?php echo $key_year?>" size="8"/>
				<?php 
				if($_SESSION['level']==ADMINISTRATOR){
					$result=get_teacher_list();
				?>
				<span><?php echo TUTOR?>:</span>
				<select name="key_teacher">
				<?php 
					if(mysql_num_rows($result)!=0){
						while(($row=mysql_fetch_array($result))!=false){
				?>
					<option value="<?php echo $row['USERID']?>" <?php if(isset($key_teacher)){default_teacher($row['USERID'],$key_teacher);}?> ><?php echo $row['USERNAME']?></option>
				<?php 
						}
					}else{
				?>
					<option value=""></option>
				<?php 
					}
				?>
				</select>
				<?php 
				}
				?>
				<span><?php echo SORTKEY?>:</span>
				<select name="key_sort">
					<option value="USERNAME" <?php if(isset($key_sort)) default_sort('USERNAME',$key_sort)?>><?php echo AUTHOR?></option>
					<option value="PUBLISHDATE" <?php if(isset($key_sort)) default_sort('PUBLISHDATE',$key_sort)?>><?php echo YEAR?></option>
				</select>
				<input type="submit" value="<?php echo SEARCH?>" style="width:50px;height:24px;"/>
			</form>
			</div>
			<div id="weeklyreport" style="margin-top:15px;">
			<?php 	
			?>
				<table class="temptable">
				<tr>
					<th><?php echo THESISTITLE?></th>
					<th><?php echo PUBLISHPLACE?></th>
					<th><?php echo THESISYEAR?></th>
					<th><?php echo SEARCHCODE?></th>
					<th><?php echo AUTHOR?></th>
				</tr>
				<?php 
					if(isset($_SESSION['key_year'])&&isset($_SESSION['key_sort'])){
						if(isset($_SESSION['key_teacher'])){
							$result=get_admin_thesis($_SESSION['key_year'],$_SESSION['key_teacher'],$_SESSION['key_sort']);
						}else{
							$result=get_teacher_thesis($_SESSION['userid'],$_SESSION['key_year'],$_SESSION['key_sort']);
						}
					
					if(mysql_num_rows($result)!=0){
					while(($row=mysql_fetch_array($result))!=false){
				?>
					<tr>
						<td width="300"><?php echo $row['TITLE']?></td>
						<td width="150"><?php echo $row['PUBLISHER']?></td>
						<td width="80"><?php echo $row['PUBLISHDATE']?></td>	
						<td width="150"><?php echo $row['SEARCHCD']?></td>
						<td width="80"><?php echo $row['USERNAME']?></td>
					</tr>
				<?php 
					}
					}else{
				?>
				<tr><td colspan=5><?php echo NOREPORT?></td></tr>
				<?php 		
					}
					mysql_close();
				?>
				</table>
			<?php 
				}else{
			?>
					<tr><td colspan=5><?php echo NOREPORT?></td></tr>
			<?php 
				}
			?>
			</div>
		</div>
	</div>
</div>
</div>
</body>
</html>

